package com.yuantu.judiciary.model.dto;

import com.yuantu.judiciary.model.enums.EndpointType;
import com.yuantu.judiciary.model.enums.OrganizationType;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * 用户账号信息
 *
 * @author syw
 * @since 2023-08-03
 **/
@Data
@NoArgsConstructor
public class AccountInfoDTO implements UserDetails {

    private Long userId;
    private String username;
    private String password;
    private List<GrantedAuthority> authorities;
    private Long accountId;
    private Long organizationId;
    private OrganizationType type;
    private EndpointType endpoint;

    public AccountInfoDTO (Long userId, String username, String password, List<GrantedAuthority> authorities) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    public AccountInfoDTO (Long accountId, String username, Long organizationId, OrganizationType type, EndpointType endpoint) {
        this.accountId = accountId;
        // todo 企业信息暂时不用
//        this.organizationId = organizationId;
//        this.type = type;
        this.username = username;
        this.endpoint = endpoint;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public Long getAccountId() {
        return accountId;
    }

    public Long getOrganizationId() {
        return organizationId;
    }

    public OrganizationType getType() {
        return type;
    }

    public Long getUserId() {
        return userId;
    }

    public EndpointType getEndpoint() {
        return endpoint;
    }

}
